package com.cskaoyan.day6;


class Item {
    String name;
    double price;
    String category;

    public Item(String name, double price, String category) {
        this.name = name;
        this.price = price;
        this.category = category;
    }

    public double buyObject(double money) {
        if (money >= this.price) {
            return money - price;
        }
        return -1;
    }
}

public class Test {

    public static void main(String[] args) {
        Item phone = new Item("Samsung Galaxy S21", 8000, "phone");
        Item furniture = new Item("海尔冰箱", 3000, "家具");
        Item commodity = new Item("海飞丝洗发水", 30, "日用品");
        double remain1 = phone.buyObject(3000);
        if (remain1 >= 0) {
            System.out.println(phone.name + "被卖出，剩余:" + remain1 + "元");
        } else {
            System.out.println("金钱不足，购买失败");
        }
        double remain2 = furniture.buyObject(3000);
        if (remain2 >= 0) {
            System.out.println(furniture.name + "被卖出，剩余:" + remain2 + "元");
        } else {
            System.out.println("金钱不足，购买失败");
        }
        double remain3 = commodity.buyObject(3000);
        if (remain3 >= 0) {
            System.out.println(commodity.name + "被卖出，剩余:" + remain3 + "元");
        } else {
            System.out.println("金钱不足，购买失败");
        }
    }


}
